package controller;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import model.UserDTO;
import model.UserSearchNameDTO;

import bizlogic.UserManager;

/**
 * Servlet implementation class StaffSearchServlet
 */
@WebServlet("/StaffSearchServlet")
public class StaffSearchServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public StaffSearchServlet() {
			// TODO Auto-generated constructor stub
			super();
		}   	
		
		/* (non-Java-doc)
		 * @see javax.servlet.http.HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
		 */
		protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
			searchRequest(request, response);
		}  	
		
		/* (non-Java-doc)
		 * @see javax.servlet.http.HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
		 */
		protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
			searchRequest(request, response);
		}   
		
		private void searchRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
			int userId = Integer.parseInt(request.getParameter("userId"));
			UserDTO userlist = new UserDTO();
			UserManager um = new UserManager();
			userlist = um.findbyId(userId);
			request.setAttribute("staff", userlist);
			RequestDispatcher rd = request.getRequestDispatcher("/ManageStaff.jsp");
			rd.forward(request, response);
		}

}
